﻿using HY.Common;
using HY.Entity;
using HY.Service;
using HY.Web.Controllers;
using HY.Web.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace HY.Web.Areas.Resource.Controllers
{
    public class Show3DController : BaseController
    {
        LocationService service = new LocationService();

        public ActionResult Show3D()
        {
            ViewBag.Url3D = "https://www.thingjs.com/pp/a4028f2bcd5aee9d336fcd15";
            return View();
        }

        public ActionResult ShowRent(int? id)
        {
            ParkService parkService = new ParkService();
            var park = parkService.GetById<Park>(id);
            ViewBag.Url3D = park.Url3D;
            return View();
        }

        public ActionResult ShowPosition(int? ParkID,string Code)
        {
            ParkService parkService = new ParkService();
            var park = parkService.GetById<Park>(ParkID);
            ViewBag.Url3D = park.Url3D;
            ViewBag.Code = Code;
            return View();
        }

        public ActionResult ShowWalk(int? id)
        {
            ParkService parkService = new ParkService();
            var park = parkService.GetById<Park>(id);
            ViewBag.Url3D = park.Url3D;
            return View();
        }

        [HttpPost]
        [AllowAnonymous]
        public JsonResult ShowRent_Ajax()
        {
            ReturnModel returnModel = new ReturnModel();
            try
            {
                var list = service.EFGetMany<Location>(l => l.IsDeleted == false).Select(s => new { name = s.Code, 面积 = s.Area.ToString(), 长度 = s.Length.ToString(), 宽度 = s.Width.ToString(), 高度 = s.Height.ToString(), 租赁 = s.IsRented ? "已租赁" : "未租赁" });
                returnModel.count = list.Count();
                returnModel.data = list;
                returnModel.msg = "获取租赁信息成功";
            }
            catch (Exception ex)
            {
                returnModel = base.GetReturnModel(ex);
                returnModel.msg = "获取租赁信息失败";
                LogHelper.Error(ex);
            }
            Response.Headers.Add("Access-Control-Allow-Origin", "*");
            return Json(returnModel);
        }
    }
}